#!/bin/sh
#
# When QA apps are changed, this script
# (a) remakes the app, and checks make status
# (b) finds and runs all the ../[0-9]* scripts that run the app
#

sts=1
tmp=/var/tmp/check_app_ok_$$
trap "rm -f $tmp.*; exit \$sts" 0 1 2 3 15

for app
do
    cd src

    echo -n "$app:"
    if [ -x "$app" ]
    then
	rm "$app"
	if make "$app" >$tmp.out 2>&1
	then
	    :
	else
	    echo
	    cat $tmp.out
	    echo "Arrgh: make $app failed!"
	    exit
	fi
    fi
    if [ -x "$app" ]
    then
	:
    else
	echo
	echo "Arrgh: failed to remake $app executable!"
	exit
    fi

    cd ..

    seqs=`grep -E -l "src/$app( |$)" [0-9][0-9]*[0-9] | tr '\012' ' ' | sed -e 's/  *$//'`

    if [ -z "$seqs" ]
    then
	echo
	echo "Warning: cannot find $app in any QA tests"
	continue
    fi
    echo "(tests: $seqs)"

    ./check -l $seqs >$tmp.out 2>&1

    sed <$tmp.out \
    	-e '/^PMDA probe:/d' \
	-e '/^[0-9][0-9]* [0-9][0-9]*s \.\.\.$/d' \
    # end

done

sts=0
exit

